<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2024/2/2 0002
 * Time: 14:34
 */

namespace app\common\taglib;


use think\auth\Auth;
use think\template\TagLib;

class MyTag extends TagLib
{
    protected $tags = [
        'auth' => ['attr' => 'rule', 'close' => 1]
    ];

    /**
     * 权限判断标签
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagAuth($tag, $content)
    {
        $rule = $tag['rule'];
        $auth = new Auth();
        $uid = session('uid');
        if ($uid != 1) {
            $res = $auth->check($rule, $uid);
            $parseStr  = '<?php if(' . intval($res) . '): ?>' . $content .'<?php endif; ?>';
            return $parseStr;
        }
        return $content;
    }
}